package com.lcredu.ajax.servlet;/**
 * @author 黎长容
 * @date 2025-07-04 11:04
 */

import com.google.gson.Gson;
import com.lcredu.ajax.dao.UserDao;
import com.lcredu.ajax.entity.User;
import com.lcredu.ajax.service.UserService;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

@WebServlet(name = "JqueryUserServlet", urlPatterns = "/JqueryUserServlet")
public class JqueryUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=utf-8");
        String uname = request.getParameter("uname");
        String date = request.getParameter("date");
        System.out.println("data=" + date);
        //连接数据库进行返回
        String userJson = new UserService().getUserJson(uname);
        if (userJson.equals(" ")) {
            User user = new User(100, "", "", "");
            Gson gson = new Gson();

            response.getWriter().write(gson.toJson(user));
        } else {
            System.out.println("userJson=" + userJson);
            
            response.getWriter().write(userJson);
        }


    }
}